Skip to content

Conversation

@gribnoysup
Copy link
Collaborator

This patch updates the sidebar to show the loading state with placeholders list while we're loading connections (both for web and desktop, although loading in desktop from disc is too fast to notice).

Kapture 2025-02-11 at 19 29 35

To be able to read this state I'm adding a new hook to the compass-connections + to be able to test it I'm changing the logic in the compass-testing-library to explicitly allow to skip sync preloading of connections (in most cases we want them to be preloaded, so I'm making this behavior an opt-in through passing null)

@gribnoysup gribnoysup added the no release notes Fix or feature not for release notes label Feb 11, 2025
@github-actions github-actions bot added the feat label Feb 11, 2025

export function getInitialConnectionsStateForConnectionInfos(
connectionInfos: ConnectionInfo[] = []
connectionInfos: ConnectionInfo[] | null
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should've been like that from the beginning instead of falling back on empty array and building logic around it, but it's only used in tests so have no real effect on anything until now

@gribnoysup gribnoysup force-pushed the compass-8876-initial-loading-state-for-the-sidebar branch from 9ade8cc to e13c3d4 Compare February 11, 2025 18:37
</div>
{connections.length > 0 && (
<>
<NavigationItemsFilter
Copy link
Collaborator Author

@gribnoysup gribnoysup Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double-check with design as I couldn't find this explicitly mentioned, but in designs we show search bar while loading, so it would be weird to yank it out when we finished, it's a noticeable and annoying visual jump, so I'm continuing to show it, just similarly disabled as when loading

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[no action] sgtm. I was going to suggest testing by deliberately hanging the load indefinitely and just see how many things you can click in the UI that you shouldn't be able to click. sounds like you experimented with that which is good!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can definitely extend the test I added to do that to some extent, good suggestion, thanks!

* the connections
*/
connections?: ConnectionInfo[];
connections?: ConnectionInfo[] | null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nonblocking] think about whether you want "null" to have different semantics from "missing" or "empty." It's a common source of bugs that the meaning of null gets overloaded and it turns up to mean different things in a couple different layers. In this case you can make the type ConnectionInfo[] | no-preload to force English meaning to appear in the code when you make the "null" choice.

Copy link
Collaborator Author

@gribnoysup gribnoysup Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fair, I'll switch it for tests helper to be something like that. Main reason I'm not putting much effort into this, is that it's literally two test cases that want this to be disabled, but it's not a great reason to not to put a bit more effort into it, so thanks for holding me accountable 😄

onFailToLoadConnections: initialProps.onFailToLoadConnections,
});
const store = configureStore(
initialProps.preloadStorageConnectionInfos ?? null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nonblocking] similar to the above point, is there a way we can better help the reader keep track of what null/undef mean as they read through different parts of the code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, honestly I think I shouldn't have changed this file at all. Undefined (optional) props are a common pattern in React and from component props perspective this should just still expect preloads to either be passed, then do a thing, or not, then do nothing in all the places, no need to make it expect null in some places, it's not really different from "no value" case here

</div>
{connections.length > 0 && (
<>
<NavigationItemsFilter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[no action] sgtm. I was going to suggest testing by deliberately hanging the load indefinitely and just see how many things you can click in the UI that you shouldn't be able to click. sounds like you experimented with that which is good!

);
};

const placeholderListStyles = css({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was also the option of skeleton loader in leafygreen, I think Simon suggested it in the jira, did you want to try that out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a follow-up ticket for that. Our component that we already use in other parts of the navigation tree (and this is why I used it here) is basically proto version of the leafygreen Skeleton, we implemented it before skeleton component existed. We should switch to leafygreen version, but I don't want to make this refactoring part of this PR, I also don't want to leave two different placeholders hanging around in the codebase

…licit in test helpers; extend the test to check for disabled elements
@gribnoysup gribnoysup merged commit a20d2a2 into main Feb 12, 2025
34 checks passed
@gribnoysup gribnoysup deleted the compass-8876-initial-loading-state-for-the-sidebar branch February 12, 2025 12:47
@gribnoysup
Copy link
Collaborator Author

Merging because you mentioned that comments are non-blocking, but take a look and tell me what you think, I'm happy to follow up if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat no release notes Fix or feature not for release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants